#include <iostream>
// 被追求者类
class SchoolGirl {
    public:
    SchoolGirl(){}
    SchoolGirl(std::string name):name_(name){}
    std::string getName(){return name_;}
    void setName(std::string name){name_ = name;}
    private:
    std::string name_;
};

// 送礼物的接口类
class Interface {
    public:
    virtual void GiveDolls() = 0;
    virtual void GiveFlowers() = 0;
    virtual void GiveChocolates() = 0;
};


// 追求者类
class Pursuit : public Interface {
    public:
    Pursuit(SchoolGirl* mm):mm_(mm){}
    virtual void GiveDolls(){
        std::cout << mm_->getName() << " 送你洋娃娃" << std::endl;
    }
    virtual void GiveFlowers() {
        std::cout << mm_->getName() << " 送你鲜花" << std::endl;
    }
    virtual void GiveChocolates() {
        std::cout << mm_->getName() << " 送你巧克力" << std::endl;
    }
    private:
    SchoolGirl* mm_;
};

// 代理类
class Proxy : public Interface {
    public:
    Proxy(SchoolGirl* mm){
        gg_ = new Pursuit(mm);
    }
    ~Proxy() {
        if (gg_ != nullptr) {
            delete gg_;
            gg_ = nullptr;
        }
    }
    virtual void GiveDolls() {
        gg_->GiveDolls();
    }
    virtual void GiveFlowers() {
        gg_->GiveFlowers();
    }
    virtual void GiveChocolates() {
        gg_->GiveChocolates();
    }  
    private:
    Pursuit* gg_;
};


int main() {
    std::cout << "Hello proxy pattern!!!" << std::endl;
    SchoolGirl* jiaojiao = new SchoolGirl("娇娇");
    Proxy* daili = new Proxy(jiaojiao);
    daili->GiveDolls();
    daili->GiveFlowers();
    daili->GiveChocolates();
    delete jiaojiao;
    delete daili;
    jiaojiao = nullptr;
    daili = nullptr;
    return 0;
}